﻿@{
    ViewBag.Title = "AddDetils";
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <link href="//unpkg.com/layui@2.9.16/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <div class="layui-container" style="padding: 20px;">

       
       <form class="layui-form" action="">
     




                <div class="layui-inline">
                    <label class="layui-form-label">销售单号</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="SalesOrderCode" name="SalesOrderCode" placeholder="可不填写，自动生成"  disabled>
                    </div>
                </div>



                <div class="layui-inline">
                    <label class="layui-form-label">商品编号</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="ProductCode" name="ProductCode">
                    </div>
                </div>


                <div class="layui-inline">
                    <label class="layui-form-label">客户编号</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="CustomerCode" name="CustomerCode">
                    </div>
                </div>



                <div class="layui-inline">
                    <label class="layui-form-label">客户名称</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="CustomerName" name="CustomerName">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="Maker" name="Maker">
                    </div>
                </div>

    


 

           
                <div class="layui-inline">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="CustomerPhone" name="CustomerPhone">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 110px;">发货日期</label>
                    <div class="layui-input-block">
                        <input type="date" name="MakeTime" id="MakeTime" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>
             

                <div class="layui-inline">
                    <label class="layui-form-label">销售员</label>
                    <div class="layui-input-inline">
                        <input type="text" id="CustomerContact" name="CustomerContact" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 110px;">销售日期</label>
                    <div class="layui-input-block">
                        <input type="date" name="CreateTime" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input" id="CreateTime">
                    </div>
                </div>
      

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="Remark" name="Remark" class="layui-textarea"></textarea>
                </div>
            </div>




            <div class="layui-inline">
                <label class="layui-form-label">数量</label>
                <div class="layui-input-inline">
                    <input type="text" id="Quantity" name="Quantity" class="layui-input">
                </div>
            </div>
         

       <</form>

        <table class="layui-hide" id="demo" lay-filter="test">
        </table>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="submit" lay-submit lay-filter="btnAdd">提交</button>
                <button type="button" class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>

    </div>
 

    <script src="~/libs/jquery/jquery.js"></script>
    <script src="//unpkg.com/layui@2.9.16/dist/layui.js"></script>


    <script>

        var date = new Date();
        var year = date.getFullYear();
        var month = ('0' + (date.getMonth() + 1)).slice(-2);
        var day = ('0' + date.getDate()).slice(-2);
        var randomNum = Math.floor(Math.random() * 1000).toString().padStart(3, '0');

        var SalesOrderCode = year + month + day + randomNum;

        document.getElementById('SalesOrderCode').value = SalesOrderCode;



        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格
            var form = layui.form;



            // $("#ProductCode").val(sessionStorage.getItem("ProductCode"))
            // 监听确认按钮点击事件
            form.on('submit(btnAdd)', function (data) {
                // 获取表单数据
                console.log(data);
                var formData = $('form').serializeArray();

                // 如果需要将销售单号的值手动添加到data.field中
                var salesOrderCode = document.getElementById('SalesOrderCode').value;

                var  Quantity= document.getElementById('Quantity').value;

                


               

                formData.push({ name: 'SalesOrderCode', value: salesOrderCode });

                // 发送 AJAX 请求
                $.ajax({
                    url: "/ProductSaleDetils/AddproductSalects",
                    type: "get",
                    data: formData,
                    success: function (res) {
                    
                        if (res) {
                        
                            layer.msg('保存成功', {
                                icon: 1,
                                time: 1000
                            }, function () {
                                // 可以在这里进行一些后续操作
                            });
                        }
                    }
                });

                return false; // 阻止表单默认提交
            });



            // 可在此初始化组件和操作dom
            querylist = function () {


                //执行一个 table 实例
                table.render({
                    elem: '#demo'
                    , height: 520
                    , url: '/ProductSaleDetils/GetSelecProduct'  //数据接口



                    /* , toolbar: 'default' */ //开启头工具栏，此处显示默认图标，可以自定义模板，详见文档
                    , page: {
                        limit: 3,
                        limits: [3, 6, 9, 12],
                        prev: '上一页',
                        next: '下一页',
                        first: '首页',
                        last: '尾页'
                    },


                    method: 'get', //默认：get请求
                    cols: [[ //表头
                        
                        { type: 'radio', title: '😊', fixed: true }, // 单选框
                      
                        { field: 'ProductName', title: '产品名称', width: 100 },
                        { field: 'ProductCode', title: '产品编号', width: 100 },
                        { field: 'ProductSpecification', title: '规格', width: 100 },
                        { field: 'Unit', title: '单位', width: 60 },
                        { field: 'UnitPrice', title: '单价', width: 60 },
                        
                       
                        , { fixed: 'right', width: 165, align: 'center', toolbar: '#barDemo' }

                    ]],
                    done: function () {
                        //表格绑定数据后的回调函数
                        layer.msg('权限展示完成！', {
                            icon: 1,
                            time: 1000
                        });
                    }
                });
            }


            querylist();

            table.on('radio(test)', function (obj) {
                console.log(obj.data)
                sessionStorage.setItem("ProductCode", obj.data.ProductCode)
                document.getElementById('ProductCode').value = obj.data.ProductCode;
            });


        });









    </script>
</body>
</html>
